home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Languguage OS 2
/
Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO
/
a_utils
/
expanded.lha
/
expanded
/
hdr
/
Matrix.h
< prev
next >
Wrap
C/C++ Source or Header
|
1992-03-19
|
5KB
|
192 lines
//
// Linear-Affine-Projective Geometry Package
//
// Matrix.h
//
// $Header$
//
// Austin Dahl and William J.R. Longabaugh
// University of Washington
//
// Copyright (c) 1990, 1991, 1992 Austin Dahl and William J.R. Longabaugh
// Copying, use and development for non-commercial purposes permitted.
// All rights for commercial use reserved.
// This software is unsupported and without warranty; it is
// provided "as is".
//
// Original implementation by Austin Dahl. Modified by WJRL to eliminate
// fixed maximum size and simplify operations on identity matrices.
//
// ***********************************************************************
#ifndef Matrix_h
#define Matrix_h
#include <stream.h>
#include "Lap1.h"
#include "Object.h"
#ifndef MAX_LOCAL_DIMEN
#define MAX_LOCAL_DIMEN 4
#endif
// ***********************************************************************
class RowMatrix : public Object {
public:
// Constructors and Destructors
RowMatrix();
RowMatrix(RowMatrix &m);
RowMatrix(int c);
RowMatrix(Scalar s0);
RowMatrix(Scalar s0, Scalar s1);
RowMatrix(Scalar s0, Scalar s1, Scalar s2);
RowMatrix(Scalar s0, Scalar s1, Scalar s2, Scalar s3);
~RowMatrix();
// Accessing Functions
Scalar& operator[](int c); // get cth element
int Columns();
friend RowMatrix AdjointRow(RowMatrix& rmat, int comit); // copy with row
// comit omitted
// I/O
friend ostream& operator<<(ostream& os, RowMatrix& rmat);
virtual void debug_out(ostream& os, int indent);
// Assignment
RowMatrix& operator=(RowMatrix& mat); // everyday assignment
protected:
// Member Variables
int columns; // the size
Scalar *rmr; // ptr to matrix
Scalar local[MAX_LOCAL_DIMEN]; // local storage
// for small matrices
};
// ***********************************************************************
overload ZeroMatrix;
// ***********************************************************************
class Matrix : public Object {
public:
// Constructors and Destructors
Matrix();
Matrix(Matrix &m);
Matrix(int r, int c);
Matrix(int dim); // for square matrices
Matrix(RowMatrix& rm0);
Matrix(RowMatrix& rm0, RowMatrix& rm1);
Matrix(RowMatrix& rm0, RowMatrix& rm1, RowMatrix& rm2);
Matrix(RowMatrix& rm0, RowMatrix& rm1, RowMatrix& rm2, RowMatrix& rm3);
~Matrix();
// Psuedo Constants (different for different sizes)
friend Matrix ZeroMatrix(int r, int c);
friend Matrix ZeroMatrix(int dim); // for square matrices
friend Matrix IdentityMatrix(int dim); // for square matrices
// Accessing Functions
RowMatrix& operator[](int r); // get rth row
friend Matrix Adjoint(Matrix& mat, int romit, int comit); // copy with row
// romit and
// column
// comit omitted
int Rows();
int Columns();
Boolean Is_Identity(void);
void Set_Identity(Boolean val);
// Matrix Functions
friend Scalar Det(Matrix& mat); // determinite,
// must be square matrix
friend Matrix Inverse(Matrix& mat); // must be square matrix
friend Matrix Transpose(Matrix& mat);
// Matrix Algrebra Operations
friend Matrix operator+(Matrix& mat1,
Matrix& mat2); // addition
friend Matrix operator-(Matrix& mat1,
Matrix& mat2); // subtraction
friend Matrix operator-(Matrix& mat); // negation
friend Matrix operator*(Matrix& mat1,
Matrix& mat2); // matrix multiply
friend Matrix operator*(Matrix& mat1,
Scalar scal); // scalar multiply
friend Matrix operator*(Scalar scal,
Matrix& mat); // scalar multiply
friend Matrix operator/(Matrix& mat,
Scalar scal); // scalar division
Matrix& operator=(Matrix& mat); // everyday assignment
Matrix& operator+=(Matrix& mat); // addition and assignment
Matrix& operator-=(Matrix& mat); // subtract and assignment
Matrix& operator*=(Matrix& mat); // matrix multiplication
// and assignment
Matrix& operator*=(Scalar scal); // scalar multiplication
// and assignment
Matrix& operator/=(Scalar scal); // scalar division
// and assingment
// I/O
friend ostream& operator<<(ostream& os, Matrix& mat);
virtual void debug_out(ostream& os, int indent);
protected:
// Member Variables
Boolean is_identity;
int rows; // the size
int columns;
RowMatrix *mr; // ptr to matrix
RowMatrix local[MAX_LOCAL_DIMEN]; // local storage
// for small matrices
};
// ***********************************************************************
inline int RowMatrix::Columns() {
return columns;
}
inline int Matrix::Rows() {
return rows;
}
inline int Matrix::Columns() {
return columns;
}
inline Matrix ZeroMatrix(int dim) {
return ZeroMatrix(dim, dim);
}
inline Matrix operator*(Scalar scal, Matrix& mat) {
return mat * scal;
}
inline Boolean Matrix::Is_Identity(void) {return is_identity;}
inline void Matrix::Set_Identity(Boolean val) {is_identity = val;}
// ***********************************************************************
#endif